<template>
  <div class="reportDetailContainer">
    <el-form ref="form" label-width="80px" style="margin: 40px">
      <el-form-item label="审核ID">
        <span @click="toUserInfo">{{ userid }}</span>
      </el-form-item>
      <el-form-item label="发布人">
        <a style="color: #006EFF" @click="toUserInfo">{{ nickName }}</a>
      </el-form-item>
      <el-form-item label="发布时间">
        <span>{{ createTime }}</span>
      </el-form-item>
      <el-form-item label="文字内容">
        <div style="width: 600px;border: 1px solid #cccccc;text-indent: 1.5rem;line-height: 40px;padding: 10px">
          <span>{{ commentDesc }}</span>
        </div>
      </el-form-item>
      <el-form-item label="图片内容">
        <div class="img">
          <el-image
            style="width: 100px; height: 100px"
            :src="srcList[0]"
            :preview-src-list="srcList">
            <div slot="error" class="image-slot">
            </div>
          </el-image>
        </div>
      </el-form-item>
    </el-form>
    <div class="footerBtns" style="position: absolute;bottom: 20px;left: 50%">
      <el-button type="primary">下一个</el-button>
      <el-button type="danger" @click="delData">删除</el-button>
      <el-button @click="cancel">取消</el-button>

    </div>
  </div>
</template>

<script>
import {
  delCommenData,
  delDiarytData, delReportData,
  getDiaryCommentData,
  getDiaryData,
  getDiaryDiaryData
} from '../../../../api/system/compassDataReport'
import {delCompassDiary} from "@/api/system/CompassDiary";

export default {
  name: 'ReportDetail',
  data() {
    return {
      //用户ID
      userid:"",
      nickName: '',
      createTime: '',
      commentDesc: '',
      imgUrl: [],
      //缩略图
      srcList:[],
      userId:"",
      imgContent:[]
    }
  },
  created() {
    this.getData()
  },
  methods: {
    getData() {
      const id = this.$route.query.id
      const type = this.$route.query.diary_type
      if (type === '回复') {
        //获取回复详细信息
        getDiaryCommentData(id).then(res => {
          this.userid = res.data.id
          this.createTime = res.data.createTime
          this.commentDesc = res.data.replyDesc
          this.nickName = res.data.replyUser
          this.userId=res.data.compassNormalUser.userId
          this.imgContent = res.data.fileList
          for(let imgUrl of this.imgContent){
            this.srcList.push(imgUrl.fileUrl)
          }
        })
      } else if (type === '评论') {
        getDiaryData(id).then(res => {
          this.userid = res.data.id
          this.createTime = res.data.createTime
          this.commentDesc = res.data.commentDesc
          this.nickName = res.data.compassNormalUser.nickName
          this.userId=res.data.compassNormalUser.userId
          this.imgContent = res.data.fileList
          for(let imgUrl of this.imgContent){
            this.srcList.push(imgUrl.fileUrl)
          }
        })
      } else if (type === '日记') {
        getDiaryDiaryData(id).then(res => {
          this.userid = res.data.id
          this.createTime = res.data.createTime
          this.userId=res.data.compassNormalUser.userId
          this.commentDesc = res.data.diaryDesc
          this.nickName = res.data.compassNormalUser.nickName
          this.imgContent = res.data.fileList
          for(let imgUrl of this.imgContent){
            this.srcList.push(imgUrl.fileUrl)
          }
        })
      }
    },
    delData() {
      const ids = this.$route.query.id;
      const type =this.$route.query.diary_type
      if(type==="回复"){
        this.$confirm('是否删除数据', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function() {
           delReportData(ids)
        }).then(() => {
          this.msgSuccess('删除成功')
          this.$router.push("/dataReport")
        }).catch(function() {
        })
      }else if(type==="评论"){
        this.$confirm('是否删除数据', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function() {
          delCommenData(ids)
        }).then(() => {
          this.msgSuccess('删除成功')
          this.$router.push("/dataReport")
        }).catch(function() {
        })
      }else if(type==="日记"){
        this.$confirm('是否删除数据', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function() {
          delDiarytData(ids)
        }).then(() => {
          this.msgSuccess('删除成功')
          this.$router.push("/dataReport")
        }).catch(function() {
        })
      }
    },
    //取消按钮
    cancel() {
      this.$router.push("/dataReport")
    },
  //  点击发布人跳转个人主页
    toUserInfo(){
      const uid=this.userId
      this.$router.push({
        name:"UserDetail",
        query:{
          id:uid,
        }
      })

    }
  }
}
</script>

<style scoped>

</style>
